package com.my.ecommercesystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.my.ecommercesystem.dao.OrderDao;
import com.my.ecommercesystem.dto.OrderDto;
import com.my.ecommercesystem.entity.Order;
import com.my.ecommercesystem.entity.Order_Item;
import com.my.ecommercesystem.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;

    public OrderDao getOrderDao() {
        return orderDao;
    }

    public void setOrderDao(OrderDao orderDao) {
        this.orderDao = orderDao;
    }

    @Override
    public Page<OrderDto> queryAllOrder(Integer page,Integer size,Integer user_id) {
        //调用pagehelper工具类
        PageHelper.startPage(page,size);
        Page<OrderDto> list=orderDao.findAllOrder(user_id);

        return list;
    }



    public long getUserOrderCount(Integer user_id){
        return orderDao.countOrderByUserId(user_id);
    }

    @Override
    public List<Order_Item> getOrderItem(String code) {
        return orderDao.getAllItemByOrderCode(code);
    }

    @Override
    public int freshOrderStatus(String status, String code) {
        int a =orderDao.updateOrderStatus(status,code);
        return a ;
    }
}
